package com.example.demo.factory.version3_factory;

import com.example.demo.factory.version2_多态.Operation;
import com.example.demo.factory.version2_多态.OperationAdd;
import com.example.demo.factory.version2_多态.OperationSub;

/**
 * @author keyer
 * @Description : 描述
 * Created by cyd on 2021-05-24 14:35:49
 */
public class OperationFactory {
    public static Operation createOperation(String operation) {
        Operation operationResult;
        switch (operation) {
            case "+":
                operationResult = new OperationAdd();
                break;
            case "-":
                operationResult = new OperationSub();
                break;
            default:
                throw new IllegalStateException("不支持: " + operation);
        }
        return operationResult;
    }
}
